package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import com.um.jdy.ykc.utils.YkcTimeUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Data;

import java.util.Date;

/**
 * 对时设置（运营平台->充电桩）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd56UpdateTimeRequest extends YkcCommand {

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 当前时间：7个字节
     */
    private Date nowTime;


    public Cmd56UpdateTimeRequest(int serial,String code,Date nowTime) {
        super();

        this.serial = serial;
        this.encFlag = RadixsUtil.hexToInteger("00");
        this.command = RadixsUtil.hexToInteger("56");

        this.code = code;
        this.nowTime = nowTime;

        byte[] codeByte = RadixsUtil.hexToBytes(code);
        byte[] nowTimeByte = YkcTimeUtil.toBytes(nowTime);

        ByteBuf buff = Unpooled.buffer();
        buff.writeBytes(fillZeroBytes(codeByte,7 - codeByte.length));
        buff.writeBytes(fillZeroBytes(nowTimeByte,7 - nowTimeByte.length));


        this.data = new byte[buff.readableBytes()];
        buff.readBytes(data);
        buff.release();

        postConstruct();
    }
}
